package com.leetcode.merci.lc500;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by bowen on 2017/7/24.
 */
public class Solution {
    public String[] findWords(String[] words) {
        String a1="qwertyuiop";
        String a2="asdfghjkl";
        String a3="zxcvbnm";
        List<String> result= new ArrayList<>();
        start :for(String word:words){
            if(a1.contains(word.toLowerCase().substring(0,1))){
                for(int i=1;i<word.length();i++){
                    if(!a1.contains(word.toLowerCase().substring(i,i+1)))
                        continue start;
                }
                result.add(word);
            }
            if(a2.contains(word.toLowerCase().substring(0,1))){
                for(int i=1;i<word.length();i++){
                    if(!a2.contains(word.toLowerCase().substring(i,i+1)))
                        continue start;
                }
                result.add(word);
            }
            if(a3.contains(word.toLowerCase().substring(0,1))){
                for(int i=1;i<word.length();i++){
                    if(!a3.contains(word.toLowerCase().substring(i,i+1)))
                        continue start;
                }
                result.add(word);
            }
        }
        return result.toArray(new String[result.size()]);
    }
}